﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using System.IO;

namespace Landscape.Business.FNH.Activities
{
    public class BusinessActivities
    {
        private ISession _CurrentSession;
        private bool _IsSessionInherited;

        internal ISession CurrentSession
        { get { return this._CurrentSession; } }

        internal bool IsSessionInherited
        { get { return this._IsSessionInherited; } }

        public BusinessActivities(ISession pCurrentSession)
        {
            this._CurrentSession = pCurrentSession;
            _IsSessionInherited = true;
        }

        public BusinessActivities()
        {
            _CurrentSession = NHSessionManager.GetManager().GetSession();
            _IsSessionInherited = false;
        }

        ~BusinessActivities()
        {
            if (!_IsSessionInherited && _CurrentSession != null)
            {
                _CurrentSession.Dispose();
            }
        }

        public void SaveEntity<T>(T pEntityObject)
        {
            CurrentSession.SaveOrUpdate(pEntityObject);
        }
    }
}
